package model.trader;

import java.util.List;

import model.market.MarketInformation;
import model.market.MarketManager;
import model.trader.portfolio.EvolvingPortfolioManager;
import model.trader.portfolio.PortfolioManagementStrategy;
import model.trader.trade.TradeExecutionStrategy;

/**
 * Values assets as cashflow/(required return) where required return is (risk free + beta * equity risk prem).
 * @author andy
 *
 */
public class Investor extends BaseTrader{
	
	
	//private double requiredReturn = MarketManager.shareCashflowRate;//1%
	private int noOfDaysRequiredForValueTest = 3;

	public int getNoOfDaysRequiredForValueTest() {
		return noOfDaysRequiredForValueTest;
	}

	public void setNoOfDaysRequiredForValueTest(int noOfDaysRequiredForValueTest) {
		this.noOfDaysRequiredForValueTest = noOfDaysRequiredForValueTest;
	}

	public Investor(){}
	
	public Investor(int noOfDaysRequiredForValueTest){
		this.noOfDaysRequiredForValueTest = noOfDaysRequiredForValueTest;
	}
	
	
	PortfolioManagementStrategy portfolioManager = new EvolvingPortfolioManager(); 
		//new StandardPortfolioStrategy();
	public PortfolioManagementStrategy getPortfolioStrategy() {
		return portfolioManager;
	}

	public double[] getPreferences(MarketManager market,MarketInformation marketInfo) {
		double[] prices= new double[marketInfo.getMarketPrices().length];
		
		if(market.getPeriod()<noOfDaysRequiredForValueTest){
			//we havent got enough information to trade on. stick with index basket and cash..
			return marketInfo.getMarketPrices();
		}
		//AMLOW:  maybe a liquidity premium?
		List<Double>[] assetCashflows = marketInfo.getAssetCashflows();
		for(int asset =0; asset<assetCashflows.length;asset++){
			List<Double> cashflows = assetCashflows[asset];
			double requiredReturn = marketInfo.getRiskFreeReturns().get(marketInfo.getRiskFreeReturns().size()-1)
											+marketInfo.getBeta(asset)*marketInfo.getEquityRiskPremium();
			double latestCashflow = cashflows.get(cashflows.size()-1);
			double fairPrice = latestCashflow*(marketInfo.getPeriodsInYear())/requiredReturn;
//			if(asset==0)
//				System.out.println("Fair price is "+fairPrice+" market price is "+market.getMarketPrice(asset)+
//						" required return is "+requiredReturn+" risk free is "+marketInfo.getRiskFreeReturns().get(marketInfo.getRiskFreeReturns().size()-1)
//						);
			prices[asset]=fairPrice;
			
			if(asset==0){
				System.out.println("Fair price 0 "+fairPrice);
			}
			
		}
		return prices;
		
	}

	//TradeExecutionStrategy tradeStrategy = new DemandCurveStrategy();//new LiquidityAdjustingExecutionStrategy();//ImmediateExecutionStrategy();
	public TradeExecutionStrategy getTradeStrategy() {
		//AM: return null to get the user configured or default.
		return null;
	}



}
